package eco2automotive.gui.actions;
import java.awt.event.*;
import eco2automotive.port.ConnectionControl;
import eco2automotive.gui.components.Panel_INFOLOG;
import eco2automotive.gui.components.Panel_TxRx;
import eco2automotive.gui.components.Panel_PROTOCOL;
import eco2automotive.gui.InforAlert;
import eco2automotive.lang.EN;
/** 
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
 */
public class Act_btn_PROTOCOL_SET implements ActionListener{       
    ConnectionControl connControl;
    Panel_INFOLOG InfoLog;
    Panel_TxRx txrx;
    Panel_PROTOCOL panel_protocol;
    
    /**
     * Action values
     * @param conn Connection object
     * @param InfoLog Link the object to display the information used by the app.
     * @param txrx Link the object to display the TX/RX information
     * @param panel_protocol List of protocols available
     * @see eco2automotive.gui.components.Panel_PROTOCOL
     */
    public Act_btn_PROTOCOL_SET(ConnectionControl conn,
        Panel_INFOLOG InfoLog, Panel_TxRx txrx,Panel_PROTOCOL panel_protocol){
        connControl=conn;
        this.InfoLog=InfoLog;
        this.txrx=txrx;
        this.panel_protocol=panel_protocol;
}

public void actionPerformed(ActionEvent e) 
    {          
        start();
        InfoLog.updateInfo(EN.QUICK_ACTIONS_SET_PROTOCOL+" "+panel_protocol.getSelectedProtocol());       
    }

/**
 * Start the action
 */
public void start() { 
    this.panel_protocol.setSelectedProtocol();    
    if(this.connControl!=null){
            if(connControl.getIsActiveConnection()==true){
             try{ 
                 
                  connControl.TXData("ATSP"+panel_protocol.getIDofSelectedProtocol());     //Set protocol   
                  connControl.TXData("ATDP"); //Describir
      } catch(Exception e){
            InfoLog.updateInfo(EN.QUICK_ACTIONS_ERROR);}              
            }
        }
    else{
        this.InfoLog.updateInfo(EN.PORT_ERROR_Not_Connected);
        new InforAlert("#ERROR",EN.PORT_ERROR_Not_Connected,1).showAlert();
         }        
    }
}
